<?php

namespace Phalcon\Test\Integration\Mvc\Collection;

use IntegrationTester;
use Phalcon\Test\Collections\Subs;
use Phalcon\Test\Fixtures\Traits\CollectionTrait;

/**
 * \Phalcon\Test\Integration\Mvc\Collection\BehaviorCest
 * Tests the Phalcon\Mvc\Collection component
 *
 * @copyright (c) 2011-2017 Phalcon Team
 * @link          http://www.phalconphp.com
 * @author        Andres Gutierrez <andres@phalconphp.com>
 * @author        Phalcon Team <team@phalconphp.com>
 *
 * The contents of this file are subject to the New BSD License that is
 * bundled with this package in the file LICENSE.txt
 *
 * If you did not receive a copy of the license and are unable to obtain it
 * through the world-wide-web, please send an email to license@phalconphp.com
 * so that we can send you a copy immediately.
 */
class BehaviorCest
{
    use CollectionTrait;

    public function behaviors(IntegrationTester $I)
    {
        $this->setupMongo($I);

        $I->wantToTest('using behaviors with collections');



        // Timestampable
        $subscriber = new Subs();

        $subscriber->email  = 'some@some.com';
        $subscriber->status = 'I';

        $I->assertTrue(
            $subscriber->save()
        );

        $I->assertRegExp(
            '/[0-9]{4}-[0-9]{2}-[0-9]{2}/',
            $subscriber->created_at
        );



        // Soft delete
        $total      = Subs::count();
        $subscriber = Subs::findFirst();

        $I->assertTrue(
            $subscriber->delete()
        );

        $I->assertEquals(
            'D',
            $subscriber->status
        );

        $I->assertEquals(
            $total,
            Subs::count()
        );
    }
}
